package cn.deschen.eshop.user.service.impl;

import cn.deschen.eshop.common.cache.RedisService;
import cn.deschen.eshop.generator.model.UmsRole;
import cn.deschen.eshop.user.service.UmsRoleCacheService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static cn.deschen.eshop.user.constants.UmsRoleCacheConstant.*;

/**
 * @Author hanbin_chen
 * @Description 后台角色缓存
 * @DateTime 2021/2/5 15:37
 * @Version V1.0.0
 */
@Service
@Slf4j
public class UmsRoleCacheServiceImpl implements UmsRoleCacheService {

    @Autowired
    private RedisService redisService;

    @Override
    public void setRoleById(Long roleId, UmsRole role) {
        String key = REDIS_DATABASE + REDIS_KEY_ROLE + roleId;
        redisService.set(key, role);
    }

    @Override
    public void delRoleList() {
        String key = REDIS_DATABASE + REDIS_KEY_ROLELIST;
        redisService.del(key);
    }

    @Override
    public UmsRole getRoleById(Long roleId) {
        String key = REDIS_DATABASE + REDIS_KEY_ROLE + roleId;
        return (UmsRole)redisService.get(key);
    }

    @Override
    public List<UmsRole> getRoleList() {
        String key = REDIS_DATABASE + REDIS_KEY_ROLELIST;
        return (List<UmsRole>) redisService.get(key);
    }
}
